﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System;
using Facebook.Schema;
using Facebook.Rest;
using Facebook.Session;
using Facebook.Utility;
using System.Threading;

namespace Facebook.Tests.Synchronous
{
    /// <summary>
    ///This is a test class for adminTest and is intended
    ///to contain all adminTest Unit Tests
    ///</summary>
    [TestClass()]
    public class dashboardTest : Test
    {
        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for getAppProperties
        ///</summary>
        [TestMethod()]
        public void addGlobalNewsTest()
        {

            var bundle = new dashboard_bundle(){message="global news message"};
            var news = new List<dashboard_bundle>();
            news.Add(bundle);
            var result = _apiWeb.Dashboard.AddGlobalNews(new dashboard_news() { news = news });
            Assert.IsTrue(result>0);
            var result2 = _apiWeb.Dashboard.GetGlobalNews(null);

            var dict = _apiWeb.Dashboard.ClearGlobalNews(new List<long>() { result });
        }
        /// <summary>
        ///A test for getAppProperties
        ///</summary>
        [TestMethod()]
        public void addNewsTest()
        {

            var bundle = new dashboard_bundle() { message = "news message" };
            var news = new List<dashboard_bundle>();
            news.Add(bundle);
            var result = _apiWeb.Dashboard.AddNews(new dashboard_news() { news = news }, Constants.FBSamples_UserId);
            Assert.IsTrue(result > 0);
            var result2 = _apiWeb.Dashboard.GetNews(null, Constants.FBSamples_UserId);

            var dict = _apiWeb.Dashboard.ClearNews(new List<long>() { result }, Constants.FBSamples_UserId);
        }
        /// <summary>
        ///A test for getAppProperties
        ///</summary>
        [TestMethod()]
        public void multiAddNewsTest()
        {

            var bundle = new dashboard_bundle() { message = "news message" };
            var news = new List<dashboard_bundle>();
            news.Add(bundle);
            var result = _apiWeb.Dashboard.MultiAddNews(new dashboard_news() { news = news }, new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 });
            var r = _apiWeb.Dashboard.MultiIncrementCount(new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 });
            var r2 = _apiWeb.Dashboard.MultiGetCount(new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 });
            var r3 = _apiWeb.Dashboard.MultiDecrementCount(new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 });
            var result2 = _apiWeb.Dashboard.MultiGetNews(new Dictionary<long, List<string>>() { { Constants.FBSamples_UserId, null }, { Constants.FBSamples_friend1, null } });
            var result3 = _apiWeb.Dashboard.MultiSetCount(new Dictionary<long, long>() { { Constants.FBSamples_UserId, 10 }, { Constants.FBSamples_friend1, 10 } });
            var result4 = _apiWeb.Dashboard.MultiClearNews(new Dictionary<long, List<string>>() { { Constants.FBSamples_UserId, null }, { Constants.FBSamples_friend1, null } });
        }
        /// <summary>
        ///A test for getAppProperties
        ///</summary>
        [TestMethod()]
        public void publishActivityTest()
        {
            var bundle = new dashboard_bundle()
            {
                message = "{*actor*} just sponsored @:563683308!",
                action_link = new action_link() { href = "http://www.example.com/games?id=5878237", text = "Sponsor this cause" }
            };
            var result = _apiWeb.Dashboard.PublishActivity(bundle);
            Assert.IsTrue(result > 0);
            var result2 = _apiWeb.Dashboard.RemoveActivity(new List<long> { result });

//            var dict = _apiWeb.Dashboard.ClearGlobalNews(new List<long>() { result });
        }
        /// <summary>
        ///A test for getAppProperties
        ///</summary>
        [TestMethod()]
        public void getActivityTest()
        {
            var result = _apiWeb.Dashboard.GetActivity(new List<long>{108957975791810}, Constants.FBSamples_UserId);
            Assert.IsTrue(result.Count == 1);
            var result2 = _apiWeb.Dashboard.GetActivity(null, Constants.FBSamples_UserId);
            Assert.IsTrue(result2.Count > 1);
        }


        /// <summary>
        ///A test for banUsers
        ///</summary>
        [TestMethod()]
        public void MultiAddNewsTest()
        {
            var bundle = new dashboard_bundle() { message = "news message" };
            var news = new List<dashboard_bundle>();
            news.Add(bundle);

            _apiWeb.Dashboard.MultiAddNewsAsync(new dashboard_news() { news = news }, new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 }, MultiAddNewsCompleted, null);
            _apiWeb.Dashboard.MultiIncrementCountAsync(new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 }, MultiIncrementCountCompleted, null);
            _apiWeb.Dashboard.MultiGetCountAsync(new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 }, MultiGetCountCompleted, null);
            _apiWeb.Dashboard.MultiDecrementCountAsync(new List<long> { Constants.FBSamples_UserId, Constants.FBSamples_friend1 }, MultiDecrementCountCompleted, null);
            _apiWeb.Dashboard.MultiSetCountAsync(new Dictionary<long, long>() { { Constants.FBSamples_UserId, 10 }, { Constants.FBSamples_friend1, 10 } }, MultiSetCountCompleted, null);
            _apiWeb.Dashboard.MultiClearNewsAsync(new Dictionary<long, List<string>>() { { Constants.FBSamples_UserId, null }, { Constants.FBSamples_friend1, null } }, MultiClearNewsCompleted, null);
            _apiWeb.Dashboard.MultiGetNewsAsync(new Dictionary<long, List<string>>() { { Constants.FBSamples_UserId, null }, { Constants.FBSamples_friend1, null } }, MultiGetNewsCompleted, null);
        }
        /// <summary>
        ///A test for banUsers
        ///</summary>
        [TestMethod()]
        public void ClearNewsTest()
        {
            var bundle = new dashboard_bundle() { message = "news message" };
            var news = new List<dashboard_bundle>();
            news.Add(bundle);
            _apiWeb.Dashboard.AddNewsAsync(new dashboard_news() { news = news }, Constants.FBSamples_UserId, AddNewsCompleted, null);

        }
        /// <summary>
        ///A test for banUsers
        ///</summary>
        [TestMethod()]
        public void ClearGlobalNewsTest()
        {
            var bundle = new dashboard_bundle() { message = "news message" };
            var news = new List<dashboard_bundle>();
            news.Add(bundle);
            _apiWeb.Dashboard.AddGlobalNewsAsync(new dashboard_news() { news = news }, AddGlobalNewsCompleted, null);
            _apiWeb.Dashboard.AddNewsAsync(new dashboard_news() { news = news }, Constants.FBSamples_UserId, AddNewsCompleted, null);

        }
        /// <summary>
        ///A test for banUsers
        ///</summary>
        [TestMethod()]
        public void ActivityTest()
        {
            var bundle = new dashboard_bundle()
            {
                message = "{*actor*} just sponsored @:563683308!",
                action_link = new action_link() { href = "http://www.example.com/games?id=5878237", text = "Sponsor this cause" }
            };
            _apiWeb.Dashboard.PublishActivityAsync(bundle, PublishActivityCompleted, null);
            _apiWeb.Dashboard.GetActivityAsync(null, Constants.FBSamples_UserId, GetActivityCompleted, null);
            Thread.Sleep(10000);
        }
        /// <summary>
        ///A test for banUsers
        ///</summary>
        [TestMethod()]
        public void GetNewsTest()
        {
            var bundle = new dashboard_bundle() { message = "news message" };
            var news = new List<dashboard_bundle>();
            news.Add(bundle);
            _apiWeb.Dashboard.AddNewsAsync(new dashboard_news() { news = news }, Constants.FBSamples_UserId, AddNewsCompleted, null);


        }
        private void MultiAddNewsCompleted(Dictionary<string, object> result, Object state, FacebookException e)
        {
        }
        private void MultiIncrementCountCompleted(Dictionary<string, bool> result, Object state, FacebookException e)
        {
        }
        private void GetActivityCompleted(List<dashboard_activity> result, Object state, FacebookException e)
        {
        }
        private void AddNewsCompleted(long result, Object state, FacebookException e)
        {
            _apiWeb.Dashboard.GetNewsAsync(null, Constants.FBSamples_UserId, GetNewsCompleted, null);

        }
        private void GetNewsCompleted(List<dashboard_news> result, Object state, FacebookException e)
        {
            _apiWeb.Dashboard.ClearNewsAsync(new List<long> { long.Parse(result[0].news_id) }, Constants.FBSamples_UserId, ClearNewsCompleted, null);
        }
        private void PublishActivityCompleted(long result, Object state, FacebookException e)
        {
            _apiWeb.Dashboard.GetActivityAsync(null, Constants.FBSamples_UserId, GetActivityCompleted, null);

        }
        private void AddGlobalNewsCompleted(long result, Object state, FacebookException e)
        {
            _apiWeb.Dashboard.ClearGlobalNewsAsync(new List<long> { result }, ClearGlobalNewsCompleted, null);
        }
        private void ClearGlobalNewsCompleted(Dictionary<string, bool> result, Object state, FacebookException e)
        {
        }
        private void ClearNewsCompleted(Dictionary<string, bool> result, Object state, FacebookException e)
        {
        }
        private void MultiGetCountCompleted(Dictionary<string, int> result, Object state, FacebookException e)
        {
        }
        private void MultiDecrementCountCompleted(Dictionary<string, bool> result, Object state, FacebookException e)
        {
        }
        private void MultiGetNewsCompleted(Dictionary<string, List<dashboard_news>> result, Object state, FacebookException e)
        {
        }
        private void MultiSetCountCompleted(Dictionary<string, bool> result, Object state, FacebookException e)
        {
        }
        private void MultiClearNewsCompleted(Dictionary<string, Dictionary<string, object>> result, Object state, FacebookException e)
        {
        }
    }
}
